package per.zqx.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

/**
 * RabbitMqConfig,
 *
 * @author Sa, Zhang 2021-08-15 17:10
 */
@Configuration
public class RabbitMqConfig {

    @Bean
    public FanoutExchange orderExchange() {
        return new FanoutExchange("acid_order_exchange", true, false);
    }

    @Bean
    public Queue orderQueue() {
        Map<String, Object> args = new HashMap<>();
        // 设置死信交换机
        args.put("x-dead-letter-exchange", "dead-queue-exchange");
        return new Queue("acid.order.queue", true, false, false, args);
    }

    @Bean
    public Binding orderBinding() {
        return BindingBuilder.bind(orderQueue()).to(orderExchange());
    }
}
